package com.clock.web.controller.shop;

import com.clock.common.annotation.Log;
import com.clock.common.core.controller.BaseController;
import com.clock.common.core.domain.AjaxResult;
import com.clock.common.core.page.TableDataInfo;
import com.clock.common.enums.BusinessType;
import com.clock.common.utils.poi.ExcelUtil;
import com.clock.shop.domain.ShopIntegral;
import com.clock.shop.domain.dto.ExchangeCouponDTO;
import com.clock.shop.service.IShopIntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 积分Controller
 * 
 * @author ruoyi
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/shop/integral")
public class ShopIntegralController extends BaseController
{
    @Autowired
    private IShopIntegralService shopIntegralService;

    /**
     * 查询积分列表
     */
    @PreAuthorize("@ss.hasPermi('shop:integral:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopIntegral shopIntegral)
    {
        startPage();
        List<ShopIntegral> list = shopIntegralService.selectShopIntegralList(shopIntegral);
        return getDataTable(list);
    }

    /**
     * 导出积分列表
     */
    @PreAuthorize("@ss.hasPermi('shop:integral:export')")
    @Log(title = "积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopIntegral shopIntegral)
    {
        List<ShopIntegral> list = shopIntegralService.selectShopIntegralList(shopIntegral);
        ExcelUtil<ShopIntegral> util = new ExcelUtil<ShopIntegral>(ShopIntegral.class);
        util.exportExcel(response, list, "积分数据");
    }

    /**
     * 获取积分详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:integral:query')")
    @GetMapping(value = "/{integralId}")
    public AjaxResult getInfo(@PathVariable("integralId") Long integralId)
    {
        return success(shopIntegralService.selectShopIntegralByIntegralId(integralId));
    }

    /**
     * 新增积分
     */
    @PreAuthorize("@ss.hasPermi('shop:integral:add')")
    @Log(title = "积分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopIntegral shopIntegral)
    {
        return toAjax(shopIntegralService.insertShopIntegral(shopIntegral));
    }

    /**
     * 修改积分
     */
    @PreAuthorize("@ss.hasPermi('shop:integral:edit')")
    @Log(title = "积分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopIntegral shopIntegral)
    {
        return toAjax(shopIntegralService.updateShopIntegral(shopIntegral));
    }

    /**
     * 删除积分
     */
    @PreAuthorize("@ss.hasPermi('shop:integral:remove')")
    @Log(title = "积分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{integralIds}")
    public AjaxResult remove(@PathVariable Long[] integralIds)
    {
        return toAjax(shopIntegralService.deleteShopIntegralByIntegralIds(integralIds));
    }

    /**
     * 用户使用积分兑换优惠券
     */
    @Log(title = "积分", businessType = BusinessType.DELETE)
    @PostMapping("/exchangeCoupon")
    public AjaxResult remove(@RequestBody ExchangeCouponDTO exchangeCouponDTO)
    {
        return toAjax(shopIntegralService.exchangeCoupon(exchangeCouponDTO));
    }
}
